import { Entity, Column, PrimaryGeneratedColumn, UpdateDateColumn, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
import { ApiProperty} from '@nestjs/swagger';
import { IsOptional } from 'class-validator';
import { OrderGoods } from './order_goods.entities';
import { User } from './user.entities';
import { UserCoupon } from './user_coupon.entities';

@Entity()
export class Order {
  @PrimaryGeneratedColumn({type: 'mediumint'})
  id: number;

  @Column({type: 'varchar', length: 32 })
  order_sn:string;

  @Column({type: 'mediumint'})
  user_id: number;

  @Column({type: 'int'})
  order_status: number;

  @Column({type: 'tinyint'})
  shipping_status: number;

  @Column({type: 'tinyint'})
  pay_status: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 60})
  consignee: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 50})
  city: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 50})
  country: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 50})
  province: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 50})
  district: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 255})
  address: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 60})
  mobile: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 255})
  postscript: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', comment: "发送id"})
  shipping_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 120})
  shipping_name: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 64})
  pay_id: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 120})
  pay_name: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', precision: 10, scale: 2})
  shipping_fee: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', precision: 10, scale: 2, comment: "实际需要支付的金额"})
  actual_price: number;

  @Column({type: 'int'})
  integral: number;

  @Column({type: 'decimal', precision: 10, scale: 2})
  integral_money: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', precision: 10, scale: 2, comment: "订单总价"})
  order_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', precision: 10, scale: 2, comment: "商品总价"})
  goods_price: number;

  @Column({type: 'datetime'})
  add_time: Date;

  @Column({type: 'datetime'})
  confirm_time: Date;

  @Column({type: 'datetime'})
  pay_time: Date;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'int'})
  freight_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'mediumint'})
  coupon_id: number;

  @Column({type: 'decimal'})
  parent_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', width: 10, precision: 2})
  coupon_price: number;

  @Column({type: 'enum', enum: ["true","false"]})
  callback_status: boolean;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal',  precision: 10, scale: 2})
  full_cut_price: number;

  @Column({type: 'varchar', length: 32})
  shipping_no: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 1})
  order_type: string;

  @IsOptional()
  @ApiProperty({type: ()=>OrderGoods})
  @OneToMany(type => OrderGoods,orderGoods => orderGoods.order,{
    cascade:true
  })
  orderGoods:OrderGoods[]

  @ManyToOne(type => User,user => user.order)
  @JoinColumn({
    name:'user_id'
  })
  user:User

  @OneToMany(type => UserCoupon, userCoupon => userCoupon.order)
  @JoinColumn({
    name:"coupon_id"
  })
  userCoupon: UserCoupon[];
}
